From f78fc7c266b028ac90442d2d085ba3e0d566d275 Mon Sep 17 00:00:00 2001 From: Alex Burka Date: Wed, 12 Jul 2017 16:28:33 -0400 Subject: [PATCH] add test for failing package --- src/cargo/ops/cargo_install.rs | 41 ++++++++++++++++++++-------------- tests/install.rs | 14 +++++++----- 2 files changed, 32 insertions(+), 23 deletions(-) diff --git a/src/cargo/ops/cargo_install.rs b/src/cargo/ops/cargo_install.rs index afde6edde..7d91d032d 100644 --- a/src/cargo/ops/cargo_install.rs +++ b/src/cargo/ops/cargo_install.rs @@ -10,7 +10,6 @@ use std::sync::Arc; use semver::Version; use tempdir::TempDir; -use termcolor::Color::Red; use toml; use core::{SourceId, Source, Package, Dependency, PackageIdSpec}; @@ -64,9 +63,9 @@ pub fn install(root: Option<&str>, let root = resolve_root(root, opts.config)?; let map = SourceConfigMap::new(opts.config)?; - if krates.len() <= 1 { + let installed_anything = if krates.len() <= 1 { install_one(root.clone(), map, krates.into_iter().next(), source_id, vers, opts, - force, true)?; + force, true).is_ok() } else { let mut succeeded = vec![]; let mut failed = vec![]; @@ -84,27 +83,35 @@ pub fn install(root: Option<&str>, first = false; } + let mut summary = vec![]; if !succeeded.is_empty() { - opts.config.shell().status("Successfully installed", succeeded.join(", "))?; + summary.push(format!("Successfully installed {}!", succeeded.join(", "))); } if !failed.is_empty() { - opts.config.shell().status_with_color("Failed to install", failed.join(", "), Red)?; + summary.push(format!("Failed to install {} (see error(s) above).", failed.join(", "))); } - } + if !succeeded.is_empty() || !failed.is_empty() { + opts.config.shell().status("\nSummary:", summary.join(" "))?; + } + + !succeeded.is_empty() + }; - // Print a warning that if this directory isn't in PATH that they won't be - // able to run these commands. - let dst = metadata(opts.config, &root)?.parent().join("bin"); - let path = env::var_os("PATH").unwrap_or(OsString::new()); - for path in env::split_paths(&path) { - if path == dst { - return Ok(()) + if installed_anything { + // Print a warning that if this directory isn't in PATH that they won't be + // able to run these commands. + let dst = metadata(opts.config, &root)?.parent().join("bin"); + let path = env::var_os("PATH").unwrap_or(OsString::new()); + for path in env::split_paths(&path) { + if path == dst { + return Ok(()) + } } - } - opts.config.shell().warn(&format!("be sure to add `{}` to your PATH to be \ - able to run the installed binaries", - dst.display()))?; + opts.config.shell().warn(&format!("be sure to add `{}` to your PATH to be \ + able to run the installed binaries", + dst.display()))?; + } Ok(()) } diff --git a/tests/install.rs b/tests/install.rs index 93dd71fc1..bd4b20a63 100644 --- a/tests/install.rs +++ b/tests/install.rs @@ -57,9 +57,9 @@ warning: be sure to add `[..]` to your PATH to be able to run the installed bina #[test] fn multiple_pkgs() { pkg("foo", "0.0.1"); - pkg("bar", "0.0.1"); + pkg("bar", "0.0.2"); - assert_that(cargo_process("install").arg("foo").arg("bar"), + assert_that(cargo_process("install").args(&["foo", "bar", "baz"]), execs().with_status(0).with_stderr(&format!("\ [UPDATING] registry `[..]` [DOWNLOADING] foo v0.0.1 (registry file://[..]) @@ -67,12 +67,14 @@ fn multiple_pkgs() { [COMPILING] foo v0.0.1 [FINISHED] release [optimized] target(s) in [..] [INSTALLING] {home}[..]bin[..]foo[..] -[DOWNLOADING] bar v0.0.1 (registry file://[..]) -[INSTALLING] bar v0.0.1 -[COMPILING] bar v0.0.1 +[DOWNLOADING] bar v0.0.2 (registry file://[..]) +[INSTALLING] bar v0.0.2 +[COMPILING] bar v0.0.2 [FINISHED] release [optimized] target(s) in [..] [INSTALLING] {home}[..]bin[..]bar[..] -Successfully installed foo, bar +error: could not find `baz` in `registry [..]` + +Summary: Successfully installed foo, bar! Failed to install baz (see error(s) above). warning: be sure to add `[..]` to your PATH to be able to run the installed binaries ", home = cargo_home().display()))); -- 2.30.2